package com.test01.controller;

import com.test01.bean.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * author: xl
 * time: 2018/5/21 14:58
 * description:
 **/
@Controller
 public class RequestMappingController {



    @RequestMapping(value = "/test",method = RequestMethod.GET)
    public ModelAndView test(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/WEB-INF/jsp/test.jsp");
        return modelAndView;
    }


    @RequestMapping(value = "/goAdd",method = RequestMethod.GET)
    public ModelAndView goAdd(){
        return new ModelAndView("addStudent", "command", new Student());
    }

    @RequestMapping(value = "/doAdd",method = RequestMethod.POST)
     public ModelAndView doAdd(Student student){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name", student.getName());
        modelAndView.addObject("age", student.getAge());
        modelAndView.addObject("id", student.getId());
        modelAndView.addObject("message", "Hello World!");

        modelAndView.setViewName("result");
        return modelAndView;
    }



}
